
{include file="public/meta" /}


</head>

<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>业主中心</h5>
                    <div class="ibox-tools">
                        <a class="link">
                            <b>
                                <i class="layui-icon layui-icon-refresh"></i>
                            </b>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <div class="row">
                        <!--搜索框开始-->
                        <div class="col-sm-12">
                            <div class="layui-form layui-form-item">
                                <!--搜索框开始-->
                                <div class="col-sm-12">
                                    <div class="layui-form layui-form-item">
                                        <div class="layui-input-inline layui-form">
                                            <input type="text" id="keyword" class="layui-input" name="keyword" value="" placeholder="业主名" maxlength="10" autocomplete="off" />
                                        </div>
                                        <div class="layui-input-inline layui-form">
                                            <select name="type_name" lay-search="">
                                                <option value="">选择楼栋</option>
                                                {volist name="_type" id="vo"}
                                                    <option value="{$vo.type_name}">{$vo.type_name} 栋</option>
                                                {/volist}
                                            </select>
                                        </div>
                                        <div class="layui-input-inline layui-form">
                                            <select name="index_name" lay-search="">
                                                <option value="">选择单元</option>
                                                {volist name="_index" id="vo"}
                                                    <option value="{$vo.index_name}">{$vo.index_name} 栋</option>
                                                {/volist}
                                            </select>
                                        </div>
                                        <div class="layui-input-inline layui-form">
                                            <select name="home_name" lay-search="">
                                                <option value="">选择牌号</option>
                                                {volist name="_home" id="vo"}
                                                    <option value="{$vo.home_name}">{$vo.home_name} 栋</option>
                                                {/volist}
                                            </select>
                                        </div>
                                        <div class="layui-input-inline layui-form">
                                            <select name="status" lay-search="">
                                                <option value="">状态</option>
                                                <option value="0">待审核</option>
                                                <option value="1">已认证</option>
                                                <option value="2">异常</option>
                                                <option value="3">永久封停</option>
                                            </select>
                                        </div>
                                        <div class="layui-input-inline">
                                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                                            <button  class="layui-btn layui-btn-normal message">添加</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <table id="demo" class="layui-hide" lay-filter="test"></table>
                    <script type="text/html" id="opeBar">
                        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                    </script>
                    <script type="text/html" id="status">
                        {{#  if(d.status === 0){ }}
                        <button type="button" class="layui-btn layui-btn-xs layui-btn-warm">待审核</button>
                        {{#  } }}
                        {{#  if(d.status === 1){ }}
                            <button type="button" class="layui-btn layui-btn-xs layui-btn-normal">正常</button>
                        {{#  } }}
                        {{#  if(d.status === 2){ }}
                        <button type="button" class="layui-btn layui-btn-xs layui-btn-warm">异常</button>
                        {{#  } }}
                        {{#  if(d.status === 3){ }}
                            <button type="button" class="layui-btn layui-btn-xs layui-btn-danger">永久封停</button>
                        {{#  } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use('table', function(){
        var table = layui.table
            , form = layui.form;
        //第一个实例
        table.render({
            elem: '#demo'
            //,height: 312
            ,url: "{:url('admin/home/home_index')}" //数据接口
            ,page: true //开启分页
            ,response: {
                statusCode: 200 //成功的状态码，默认：0
            }
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , toolbar: '#toolbarDemo'
            , defaultToolbar: ['filter','exports'] //工具类
            , loading: true
            , id: 'test'
            ,cols: [[ //表头
                {field: 'id', title: 'ID', width:60, sort: true, fixed: 'left'}
                ,{field: 'username', title: '用户名',templet:'#plot'}
                ,{field: 'tel', title: '手机号'}
                ,{field: 'type_name', title: '楼栋'}
                ,{field: 'index_name', title: '单元门'}
                ,{field: 'home_name', title: '牌号'}
                ,{field: 'status', title: '状态',templet:'#status'}
                ,{field: 'notice', title: '备注'}
                ,{fixed: 'right', width:150, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
        });
        //监听搜索
        form.on('submit(LAY-search)', function (data) {
            //执行重载
            table.reload('test', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: data.field
            });
        });
        //监听工具条
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('真的删除么', function(index){
                    var load = layer.load();
                    $.ajax({
                        url:"{:url('admin/home/home_index_del')}",
                        type:'get',
                        dataType:'json',
                        data:{id:data.id},
                        success:function(res){
                            if (res.data == 1) {
                                layer.close(load);
                                layer.msg(res.message);
                                setTimeout('window.location.reload()',1000);
                            } else if (res.data == 0) {
                                layer.open({
                                    title: '删除失败'
                                    ,content: res.message
                                });
                            } else {
                                layer.open({
                                    title: '删除失败'
                                    ,content: '出现未知错误，如果问题一直出现，您可以联系管理员或站点留言'
                                });
                            }
                        }
                    })
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                layer.open({
                    type: 2,
                    shade: false,
                    area: ['650px','550px'],
                    maxmin: true,
                    content: "http://localhost/bd_home/public/home_index_edit.html?id="+obj.data.id,
                    zIndex: layer.zIndex, //重点1
                    success: function(layero){
                        layer.setTop(layero); //重点2
                    }
                });
            }
        });
    });
</script>
<script>
    layui.use('layer', function() {
        var $ = layui.jquery, layer = layui.layer;
        //触发事件
        $('.message').on('click', function () {
            layer.open({
                type: 2,
                shade: false,
                area: ['600px','750px'],
                maxmin: true,
                title:"业主_添加",
                content: "{:url('admin/home/home_index_add')}",
                zIndex: layer.zIndex, //重点1
                success: function(layero){
                    layer.setTop(layero); //重点2
                }
            });
        });
    });
</script>
<!-- 全局js -->
{include file="public/footer" /}
</body>

</html>
